package apiday02.collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class NewForDemo {
    public static void main(String[] args) {
        String[] str = new String[]{"one","two","three","four","five"};
        for (int i = 0; i < str.length; i++) {
            System.out.print(str[i]+" ");
        }
        System.out.println();
        for (String s: str) {//为数组时，编译时自动转换为普通for循环
            System.out.print(s+" ");
        }
        System.out.println("\n--------------------------------------------");

        Collection<String> collection = new ArrayList<>();
        collection.add("one");
        collection.add("two");
        collection.add("three");
        collection.add("four");
        collection.add("five");
        Iterator<String> iterator = collection.iterator();
        while(iterator.hasNext()){
            System.out.print(iterator.next()+" ");
        }
        System.out.println();
        for (String s:collection) {//为集合时，编译时自动转换为迭代器遍历
            System.out.print(s+" ");
        }

    }
}
